package com.hs.hlw.credit.system.common.enumeration;

/**
 * FileTypeEnum
 * @author zhb
 * @date 2018/11/23
 */
public enum FileTypeEnum {
    XLS(1, "xls"),
    XLSX(2, "xlsx"),
    DOC(3, "doc"),
    DOCX(4, "docx");

    public Integer code;
    public String value;

    FileTypeEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public static FileTypeEnum getTypeByValue(String value){
        for (FileTypeEnum ete : FileTypeEnum.values()) {
            if (ete.value.equals(value)) {
                return ete;
            }
        }
        return null;
    }

    public static FileTypeEnum getTypeByFileName(String fileName){
        if (fileName == null) {
            return null;
        }
        for (FileTypeEnum ete : FileTypeEnum.values()) {
            if (fileName.toLowerCase().endsWith("." + ete.value)) {
                return ete;
            }
        }
        return null;
    }
}
